/*
 * Copyright 2008 [rapid-framework], Inc. All rights reserved.
 * Website: http://www.rapid-framework.org.cn
 */

    define("pages/jls_Zpwh/main", [
            "../../plugins/easyui/jquery-easyui-1.5.1/jquery.easyui.min",
            "../../plugins/easyui/jquery-easyui-1.5.1/easyloader",
            "../../plugins/artTemplate/artTemplate",
            "../../common/tools",
            "../../common/componts",
            "../../common/kss",
            "../../pages/jls_Zpwh/form",
            "../../pages/jls_Jbxx/JbxxShowHide.html.js",
            "../../pages/jls_Zpwh/ZpwhShowHide.html.js"
        ],
        function(require) {
            var comonts=require("../../common/componts");
            var zpwhForm=require("../../pages/jls_Zpwh/form");
            var tmp=require("../../pages/jls_Jbxx/JbxxShowHide.html");
            var tmpZpwh=require("../../pages/jls_Zpwh/ZpwhShowHide.html");
            var kss=require("../../common/kss");
            var ryjbxxId="jbxxId";
            var zpwhId="zpwhId";
            var zpwh="zpwh";
            var selectid;
            var id;
            var jbxx="jbxx";

            var tableInit=function(){
                kss.initJbxxTable(ryjbxxId,{
                    singleSelect:true,
                    url:'/jls_jbxx/jbxxList',
                    detailFormatter : function(index, rowData) {
                        return '<table  style="height:60px;width:100%"><tr><td>户籍地详细地址：'
                            + (rowData.hjszd == null ? ""
                                : rowData.hjszd)
                            + '</td></tr><tr><td>现住地详细地址:'
                            + (rowData.xzd == null ? "" : rowData.xzd)
                            + '</td></tr><tr><td>办案单位:'
                            + (rowData.badw == null ? "" : rowData.badw)
                            + '</td></tr><tr><td>简要案情:'
                            + (rowData.aq == null ? "" : rowData.aq)
                            + '</td></tr></table>'
                    },
                    onDblClickRow:function(rowIndex, rowData){
                        if (rowData.rybh != undefined) {
                            $("input[name='ryRadio']")[rowIndex].checked = true;
                            $("#"+ryjbxxId).datagrid("selectRow", rowIndex);
                            var jbxx=$("#"+ryjbxxId).datagrid('getSelected');
                            zpwhForm.show(jbxx,{},refreshTable);

                            $('input').next().find('input[type=text]').css('background-color','#EBEBE4');
                            var myDate = new Date();
                            var str=myDate.toLocaleTimeString();
                        }
                    },
                    onClickRow:function(rowIndex, rowData){
                        if(selectid!=rowData.id){
                            $("input[name='ryRadio']")[rowIndex].checked = true;
                            selectid=rowData.id;
                        }else{
                            $("#"+ryjbxxId).datagrid("unselectRow",rowIndex);
                            $("input[name='ryRadio']")[rowIndex].checked = false;
                            $('#'+ryjbxxId).datagrid('clearSelections');
                            selectid="";
                        }
                    },
                    onSelect:function(rowIndex, rowData){
                        var jbxx = $('#'+ryjbxxId).datagrid('getSelected');
                        var flag = $("input[name='ryRadio']")[rowIndex].checked;
                        if(jbxx && !flag){
                            var rybh = jbxx.rybh;
                            $('#'+zpwhId).datagrid('loadData', { total: 0, rows: [] });
                            if (rybh != undefined) {
                                var opts = $("#"+zpwhId).datagrid("options");
                                $("#"+zpwhId).datagrid("clearSelections");
                                $('#'+zpwhId).datagrid('load',{
                                    'rybh': rybh,
                                });
                            }
                        }else {
                            $('#'+zpwhId).datagrid('loadData', { total: 0, rows: [] });
                        }
                    },
                    rightmenu:function(){
                    }

                });
                comonts.initTable(zpwhId,{
                    title: '照片维护',
                    url:"/jls_zpwh/zpwhList",
                    columns:[
                        /*{field: 'id',title: '类型',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="idRadio" id="idRadio"' + rowIndex + 'value="' + rowData.id + '" />';}},
                        {field: 'rybh',title: '是否有照片',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="rybhRadio" id="rybhRadio"' + rowIndex + 'value="' + rowData.rybh + '" />';}},*/

                        {
                            field : 'lx',
                            width : 150,
                            title:'类型',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.lx== null ? "" : row.lx)+'</span>'
                            }},
                        {
                            field : 'ispicture',
                            width : 150,
                            title:'是否有照片',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.ispicture== null ? "" : row.ispicture)+'</span>'
                            }},

                        ],
                    detailFormatter:function(index,rowData){
                        return ;
                    },
                    onClickRow:function(rowIndex, rowData){
                        if(id!=rowData.id){
                            $("input[name='zpwhRadio']")[rowIndex].checked = true;
                            $('#'+zpwhId).datagrid("selectRow", rowIndex);
                            id=rowData.id;
                        }else if(id==rowData.id){
                            $('#'+zpwhId).datagrid("unselectRow",rowIndex);
                            $("input[name='zpwhRadio']")[rowIndex].checked = false;
                            id="";
                        }
                    },
                    //双击事件
                    onDblClickRow:function(rowIndex, rowData){
                        $("input[name='zpwhRadio']")[rowIndex].checked = true;
                        $('#'+zpwhId).datagrid("selectRow", rowIndex);
                        id=rowData.id;
                        var jbxx = $('#jbxxId').datagrid('getSelected');
                        zpwhForm.show(jbxx,rowData,refreshTable);

                    },

                });
                $('#'+zpwhId).datagrid('resize',{
                    height:($(window).height() -320)
                });

            }
            var findZpwh=function(){
                var val = $("#jqjsTree").tree('getSelected');
                var s_rybh = $("#s_rybh").textbox('getValue');
                var s_xm = $("#s_xm").textbox('getValue');
                //人员状态,单选框
                var opts = $('#'+ryjbxxId).datagrid("options");
                opts.url = "/jls_jbxx/jbxxList";
                $('#'+ryjbxxId).datagrid('clearSelections');
                $('#'+ryjbxxId).datagrid('load',{
                	'xm':s_xm,
                    'rybh':s_rybh,
                });
            }
            var initJsTree=function(){
                kss.initJsTree("jqjsTree","jbxxId",{});
            }
            var bindAction=function(){
                $("#zpwh_search").on("click",function(){
                    findZpwh();
                });
                $("#zpwh_add").on("click",function(){
                    var ryjbxx=$("#"+ryjbxxId).datagrid('getSelected');
                    if(ryjbxx){
                        zpwhForm.show(ryjbxx,{},refreshTable);
                    }else{
                        $.messager.alert("提示","请先选择要录入照片的人员!","info");
                    }
                });
                $("#zpwh_update").on("click",function(){
                    var ryjbxx=$("#"+ryjbxxId).datagrid('getSelected');
                    var zpwh=$("#"+zpwhId).datagrid('getSelected');
                    if(ryjbxx&&bjjl){
                        zpwhForm.show(ryjbxxzpwh,refreshTable,{});
                        $('#rybhId').next().find('input[type=text]').css('background-color','#ebebe4');
                        $('#ryxmId').next().find('input[type=text]').css('background-color','#ebebe4');
                        $('#jshId').next().find('input[type=text]').css('background-color','#ebebe4');
                    }else{
                        $.messager.alert("提示","请选择一个在押人员!","info");
                    }
                });
                $("#zpwh_jn600d").on("click",function(){
                    var ryjbxx=$("#"+ryjbxxId).datagrid('getSelected');
                    if(ryjbxx){
                        zpwhForm.show(ryjbxx,{},refreshTable);
                    }else{
                        $.messager.alert("提示","请先选择要录入照片的人员!","info");
                    }
                });

                $(window).keydown(function(event) {
                    if (event.keyCode == 13) {
                        findzpwh();
                    }
                });
                comonts.ShowHide(jbxx,tmp);
                comonts.ShowHide(zpwh,tmpZpwh);
                $("#zpwh_print").on("click",function(){
                    var label="jls_zpwh";
                    var name="jls_zpwh";
                    var rybh=$("#"+ryjbxxId).datagrid('getSelected').rybh;
                    var url=comonts.getReportUrl(true,label,name,'rybh%3d'+rybh);
                    console.info(url);
                    addTab("Zpwh",url);
                });

            }
            var refreshTable=function(data){
                $('#'+zpwhId).datagrid('reload',{rybh:$('#'+ryjbxxId).datagrid('getSelected').rybh});
            }


            var initView=function(){
                tableInit();
                bindAction();
                initJsTree();

            }


            initView();
        });
